"""
Centralised configuration for the BIM match application.

The module exposes a ``settings`` singleton that contains application paths,
registration parameters and viewer defaults.  Import the ``settings`` object
from this module instead of hard-coding values in individual modules.
"""

from __future__ import annotations

from dataclasses import dataclass, field
from pathlib import Path


@dataclass
class PathConfig:
    """Path related settings resolved relative to the project root."""

    root: Path = field(default_factory=lambda: Path(__file__).resolve().parent.parent)
    data_dir: str = "data"
    cache_dir: str = "cache"
    registered_dir: str = "registered_ply"

    def resolve(self, *parts: str) -> Path:
        return self.root.joinpath(*parts)

    @property
    def data(self) -> Path:
        return self.resolve(self.data_dir)

    @property
    def cache(self) -> Path:
        return self.resolve(self.cache_dir)

    @property
    def registered(self) -> Path:
        return self.resolve(self.registered_dir)

    @property
    def registration_cache_file(self) -> Path:
        return self.cache / "registration_results.json"

    @property
    def metadata_file(self) -> Path:
        return self.registered / "output_metadata.json"


@dataclass
class RegistrationConfig:
    """Configuration options for point cloud registration."""

    is_small_cloud: bool = True
    max_attempts: int = 15
    random_seed: int = 42
    default_threshold: float = 0.01
    viewer_sample_points: int = 50_000
    bim_sampling_multiplier_small: int = 2
    bim_sampling_multiplier_large: int = 3


@dataclass
class ViewerConfig:
    """Defaults used by the viewer UI."""

    background_color: str = "#2D2D2D"
    point_size: int = 8


@dataclass
class Settings:
    """Root settings container."""

    paths: PathConfig = field(default_factory=PathConfig)
    registration: RegistrationConfig = field(default_factory=RegistrationConfig)
    viewer: ViewerConfig = field(default_factory=ViewerConfig)


settings = Settings()


